<?php
namespace Versal\AdminBundle\Form;
 
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Email;
use Versal\AdminBundle\Validator\Constraints\ContainsAlphanumeric;


/**
 * Description of newPHPClass
 *
 * @author jorgeflores
 */

class CrearUsuarioForm extends AbstractType{
    
    private $collRegiones;
    
    public function __construct($collRegiones = array()) {
        $this->collRegiones = $collRegiones;
    }
    
    public function buildForm(FormBuilderInterface $builder, array $options){
        
        $builder->add('username', 'text' , array( 
             'constraints' => array(new NotBlank(), new ContainsAlphanumeric())
        ));
        $builder->add('nombre', 'text' , array( 
             'constraints' => array(new NotBlank(), new ContainsAlphanumeric())
        ));                  
        $builder->add('apePaterno', 'text' , array( 
             'constraints' => array(new NotBlank(), new ContainsAlphanumeric())
        ));
        $builder->add('apeMaterno', 'text' , array( 
             'constraints' => array(new NotBlank(), new ContainsAlphanumeric())
        ));
        $builder->add('email', 'text' , array( 
             'constraints' => array(new NotBlank(), new Email())
        ));
        $builder->add('direccion', 'text' , array( 
             'constraints' => array(new NotBlank(), new ContainsAlphanumeric())
        ));
        $builder->add('numCalle', 'text' , array( 
             'constraints' => array(new NotBlank(), new ContainsAlphanumeric())
        ));
        $builder->add('region', 'choice' , array( 
                'constraints' => new NotBlank(),
                'multiple' => false,
                'choices' => $this->getRegiones(),
                'empty_value' => 'Seleccione region'
            )
        );
        $builder->add('telFijo', 'text' , array( 
             'constraints' => new ContainsAlphanumeric(),
             'required' => false
        ));
        $builder->add('telMovil', 'text' , array( 
             'constraints' => new ContainsAlphanumeric(),
            'required' => false
        ));
        
//        $builder->add('perfil', 'choice' , array(            
//              'multiple'  => true));
//        
//        $builder->add('perfilUsuario', 'choice' , array(            
//              'multiple'  => true));
        //$builder->add('dueDate', 'date', array('widget' => 'single_text'));
        $builder->add('Grabar', 'submit');
        $builder->add('Cancelar', 'button');
    }
 
    public function getName(){
        return 'usuario';
    }
    
    public function getRegiones(){
        foreach($this->collRegiones as $region)
        {
            $arrRegion[$region->getRegionId()] = $region->getNombre();
        }
        return $arrRegion;
    }
}
